/*******************************************************************************
 * Copyright 2011 @ Kapil Viren Ahuja
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package com.kapilvirenahuja.eamsteps.datareader.excel;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.Validate;

import jxl.Sheet;

import com.kapilvirenahuja.eamsteps.datareader.IDataRow;
import com.kapilvirenahuja.eamsteps.datareader.IDataTable;


/**
 * @see IDataTable
 */
public class ExcelDataTable implements IDataTable
{
    private final Sheet sheet;

    public ExcelDataTable(Sheet sheet)
    {
        Validate.notNull(sheet);

        // If validations pass, setup the Data table.
        this.sheet = sheet;
    }

    public String getName()
    {
        return this.sheet.getName();
    }

    public IDataRow getRow(int rowNumber)
    {
        return new ExcelDataRow(this.getName(), this.sheet.getRow(rowNumber));
    }

    public int getRowCount()
    {
        return this.sheet.getRows();
    }

    public List<IDataRow> getRows()
    {
        List<IDataRow> rows = new ArrayList<IDataRow>();

        int rowCount = this.getRowCount();
        for (int count = 0; count < rowCount; count++)
        {
            rows.add(this.getRow(count));
        }

        return rows;
    }
}
